/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wii.elpro.dao.hb;

import com.wii.elpro.dao.HibernateUtil;
import com.wii.elpro.dao.POInternalDAOInterface;
import com.wii.elpro.entity.Cabang;
import com.wii.elpro.entity.POInternal;
import com.wii.elpro.entity.User;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author hendro
 */
public class POInternalDAOImpl extends DAOGenericImpl implements POInternalDAOInterface{

    public POInternal getPOInternal(long id) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return (POInternal)session.load(POInternal.class, id);
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<POInternal> getPOInternals() throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT po FROM POInternal po").list();                   
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<POInternal> getPOInternals(Cabang cabang) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT po FROM POInternal po WHERE po.quotation.spdcf.inquery.cabang=:input")
                    .setParameter("input", cabang).list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<POInternal> getPOInternals(User sales) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT po FROM POInternal po WHERE po.quotation.spdcf.inquery.sales=:input")
                    .setParameter("input", sales).list();
        } catch (Exception ex) {
            throw ex;
        }
    }

}
